﻿using ATM.Common;
using ATM.Entities;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ATM.DAO
{
    public class ViewHistoryDAO
    {
        public List<ViewHistory> GetData(string a,string b,int c)
        {
            List<ViewHistory> lst_viewHis = new List<ViewHistory>();
            SqlCommand cmd = new SqlCommand("select logs.CardNo, atms.Address,logtypes.Description,Logs.LogDate,Logs.Amount,logs.Details from ATMs,logtypes,logs where logs.LogTypeID=LogTypes.LogTypeID and logs.ATMID=atms.ATMID and logs.CardNo=@CardNo and datediff(" + b + ",CAST(LogDate as Date) ,getdate())<" + c , DataConnection.GetConnection());
            cmd.Parameters.Add("@CardNo", SqlDbType.VarChar).Value = a;
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            for (int i = 0; i < dt.Rows.Count;i++ )
            {
                ViewHistory vh = new ViewHistory();
                vh.Address = dt.Rows[i]["Address"].ToString();
                vh.Type = dt.Rows[i]["Description"].ToString();
                vh.date = Convert.ToDateTime(dt.Rows[i]["LogDate"].ToString());
                vh.Amount = Convert.ToInt32(dt.Rows[i]["Amount"].ToString());
                vh.To = dt.Rows[i]["Details"].ToString();
                vh.cardNo = dt.Rows[i]["CardNo"].ToString();

                lst_viewHis.Add(vh);
            }
                return lst_viewHis;
        }
    }
}
